export class AssetManager  {
    constructor(){}
    private _asset = {};
    public loadAssetAsync<T>(path: string): Promise<T> {
        return new Promise((resolve, reject) => {
            let asset = this._asset[path];
            if (asset){
                resolve(asset);
            }else{
                cc.loader.loadRes(path, (err: any, asset: T) => {
                    if (err) {
                        cc.err("[AssetManager] --> loadAsset err", err);
                        reject();
                        return;
                    }
                    this._asset[path] = asset;
                    resolve(asset);
                });
            }
        });
    }

    public releaseAsset(path: string){
        let asset = this._asset[path];
        if(asset){
            cc.loader.releaseRes(asset);
            this._asset[path] = null;
            delete this._asset[path];
        }
    }
}
